package com.gosophia.govDoc.action.turning;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.dataDictionary.dto.DataValueDTO;
import com.gosophia.dataDictionary.ws.DataDictionaryWebService;
import com.gosophia.govDoc.common.DocumentMissionStatus;

@Scope("prototype")
@Controller("EnterDocumentHandleAction")
public class EnterDocumentHandleAction extends BaseSupportAction {

    private static final long serialVersionUID = 8639441716626404098L;
    private final Logger logger = Logger.getLogger(this.getClass());
    @Autowired
    private DataDictionaryWebService dataDictionaryWebService;

    private String importalString;
    private String jobTypesString;

    @Override
    public String _execute() throws Exception {
        logger.debug("进入公文处理action");
        jobTypesString = generateGovJobTypes();
        List<DataValueDTO> dataValueDto = new ArrayList<DataValueDTO>();
        dataValueDto = dataDictionaryWebService
                .findEnabledDataValueByEntryName("zhongyaochengdu");
        importalString = JSONArray.fromObject(dataValueDto).toString().replace(
                "\"", "\\\"");
        return SUCCESS;
    }

    private String generateGovJobTypes() {
        /*
         * List<String> jobTypes = new ArrayList<String>(); for (DocumentJobType
         * documentJobType : DocumentJobType.values()) {
         * jobTypes.add(documentJobType.toString()); }
         */

        String[] jobTypeArray = DocumentMissionStatus.PROCESSING.getJobTypes();
        return JSONArray.fromObject(jobTypeArray).toString().replace("\"",
                "\\\"");
    }

    public String getImportalString() {
        return importalString;
    }

    public void setImportalString(String importalString) {
        this.importalString = importalString;
    }

    public String getJobTypesString() {
        return jobTypesString;
    }

    public void setJobTypesString(String jobTypesString) {
        this.jobTypesString = jobTypesString;
    }

}
